package com._51cto.healthy.controller;

import com._51cto.healthy.content.R;
import com._51cto.healthy.pojo.Image;
import com._51cto.healthy.service.ImageService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/image")
public class ImageController {
    @DubboReference
    private ImageService imageService;

    @PostMapping("/add")
    @Transactional
    //添加图片
    public R addImgs(@RequestBody Image image ){
        System.out.println("image,add" + image);
        imageService.insertImg(image);
        return R.success("添加成功");
    }
    //删除图片
    @DeleteMapping("/{id}")
    public R deleteImg(@PathVariable("id") Integer id){
        imageService.deleteById(id);
        return R.success("删除成功");
    }
    //修改图片
    @PutMapping("/update")
    public R updateImg(@RequestBody Image image){
        imageService.updateById(image);
        return R.success("修改成功");
    }
    //查询所有图片
    @GetMapping("/queryAll")
    public R queryAll(Image image){
        List<Image> imageList = imageService.queryAll();
        return R.success(imageList,"查询成功");
    }


}
